<template>
  <div style="padding:40px;">
    <el-alert :closable="false" title="电子票据" />
    <el-form :inline="true" ref="form" :model="form" label-width="120px">
      <el-row>
        <el-form-item label="开票时间">
          <el-date-picker
            type="date"
            placeholder="开始日期"
            v-model="form.date1">
          </el-date-picker>~
          <el-date-picker
            type="date"
            placeholder="截止日期"
            v-model="form.date2">
          </el-date-picker>
        </el-form-item>
        <el-select v-model="value" clearable placeholder="业务类型">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-row>
      <el-row>
        <el-form-item>
          <el-form-item label="系统发票号">
            <el-input placeholder="输入发票号" clearable v-model="form.input"/>
          </el-form-item>
          <el-form-item label="姓名">
            <el-input placeholder="输入姓名" clearable v-model="form.name"/>
          </el-form-item>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="getBillList">查询票据</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onCancel">重置</el-button>
        </el-form-item>
      </el-row>
    </el-form>
    <el-form>
      <el-alert :closable="false" title="开票记录"/>
      <el-table
        :data="tableData1"
        border
        style="width: 100%">
        <el-table-column
          fixed
          prop="rowIndex"
          label="序号"
          width="50"
          align="center">
          <template slot-scope="scope">
            <span>{{scope.$index+(pageInfo.currentPage - 1) * pageInfo.pageSize + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="billNo" label="系统发票号" align="center"></el-table-column>
        <el-table-column prop="patientName" label="姓名" align="center"></el-table-column>
        <el-table-column prop="totalAmount" label="金额" align="center"></el-table-column>
        <el-table-column prop="type" label="票据类型" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.type === '01'">住院</span>
            <span v-else>门诊</span>
          </template>
        </el-table-column>
<!--        <el-table-column prop="idCard" label="身份证号" align="center"></el-table-column>-->
        <el-table-column
          prop="random"
          align="center"
          label="校验码">
        </el-table-column>
        <el-table-column prop="invoiceCode" label="电子票据代码" align="center"></el-table-column>
        <el-table-column prop="invoiceNumber" label="电子票据号码" align="center"></el-table-column>
        <el-table-column prop="issueDate" label="开票时间" align="center"></el-table-column>
<!--        <el-table-column prop="invoiceUrl" label="票据链接" align="center"></el-table-column>-->
        <el-table-column
          fixed="right"
          label="操作"
          width="100"
          prop="invoiceUrl">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="getInfo(scope.row.pictureUrl)">票据预览</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-form>
    <el-pagination
      hide-on-single-page
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="pageInfo.currentPage"
      :page-sizes="[5, 10, 20, 50]"
      :page-size="pageInfo.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalNumber"></el-pagination>
  </div>
</template>
<script>
import {postAction} from "@/api/manage";

export default {
  data() {
    return {
      options: [{
        value: '02',
        label: '门诊'
      }, {
        value: '01',
        label: '住院'
      }],
      value: '',
      // pageNum: 1,
      // pageSize: 5,
      totalNumber:0,
      //分页
      pageInfo: {
        currentPage: 1,
        pageSize: 5
      },
      tableData1: [],
      form: {
        date1: '',//开始时间
        date2: '',//截止时间
        input: '',//系统发票号
        name: '' //患者姓名
      },
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      urls: {
        getBillRecordsList: '/nmyx/leantech/invoicing-list' //获取开票记录清单
      }
    }
  },
  methods: {
    getInfo(url) {
      let netUrl = url
      window.open(netUrl,'_blank')
    },
    getBillList() {
      var pageNum = this.pageInfo.currentPage.toString()
      var pageSize = this.pageInfo.pageSize.toString()
      var type = this.value
      if (type === '') {
        this.$message.error("业务类型不能为空！！！")
        return
      }
      var patientName = this.form.name
      var billNo = this.form.input
      var beginTime = ''
      var endTime = ''
      var t1 = this.form.date1
      var t2 = this.form.date2
      if ('' != t1) {
        beginTime = t1.getFullYear() + '-' + (t1.getMonth() + 1) + '-' + t1.getDate()
      }
      if ('' != t2) {
        endTime = t2.getFullYear() + '-' + (t2.getMonth() + 1) + '-' + t2.getDate()
      }
      var params = {
        pageNum,pageSize,type,billNo,patientName,beginTime,endTime
      }
      postAction(this.urls.getBillRecordsList,params).then(res =>{
        console.log("billRecords",res)
        if (res.code === 'SUCCESS') {
          if (res.data.successBillVoList.length !== 0) {
            this.tableData1 = res.data.successBillVoList
            console.log("this tabledata....",this.tableData1)
            this.totalNumber = res.data.total
          } else {
            this.tableData1 = []
            this.totalNumber = 0
          }
        } else {
          this.$message({ message: '操作失败, ' + res.message, type: 'error'})
        }
      })
    },
    onSubmit() {
      this.$message('submit!')
    },
    onCancel() {
      this.$message({
        message: '重置成功',
        type: 'warning'
      })
      this.tableData1 = []
      this.totalNumber = 0
      this.pageInfo.currentPage = 1
      this.pageInfo.pageSize = 5
      this.form.date1 = ''
      this.form.date2 = ''
      this.value = ''
    },
    handleSizeChange(val) {
      this.pageInfo.pageSize = val;
      console.log("size",val)
      this.getBillList()
    },
    handleCurrentChange(val) {
      this.pageInfo.currentPage = val;
      this.getBillList()
    }
  }
}
</script>

<style scoped>
  .line{
    text-align: center;
  }
</style>
